package com.itheima.d6Regex;

import java.util.Scanner;

public class RegexDemo1 {
    public static void main(String[] args) {
        //校验手机、电话、邮箱
        Scanner sc = new Scanner(System.in);
       // boolean checkPhone = checkPhone(sc);
        //System.out.println("手机号?"+checkPhone);
        checkEmail(sc);
        checkFixedPhone(sc);
    }
    public static  boolean checkPhone(Scanner sc){
        boolean flag = false;
        while (!flag) {
            System.out.println("输入手机号:");
            String telPhone = sc.next();
            boolean matches = telPhone.matches("1{1}[3-9]\\d{9}");
            if (matches) {
                flag = true;
            }
        }
        return true;
    }
    public static  void  checkEmail(Scanner sc){
        while (true) {
            System.out.println("请输入邮箱");
            String email = sc.next();
            boolean matches = email.matches("\\w{1,}@[a-z]{2,}(\\.[a-z]{2,}){1,2}");
            if (matches){
                System.out.println("邮箱正确");
                break;
            }else{
                System.out.println("有误！");
            }
        }
    }
    public static void checkFixedPhone(Scanner sc){
        while (true) {
            System.out.println("请输入座机号码");
            String fixedPhone = sc.next();
            boolean matches = fixedPhone.matches("0\\d{3,7}-?\\d{5,20}");
            if (matches){
                System.out.println("座机号码正确");
                break;
            }else{
                System.out.println("有误！");
            }
        }
    }


}
